package com.learn.mq.controller;

import com.alibaba.fastjson2.JSON;
import com.learn.mq.beans.Person;
import com.learn.mq.param.Message;
import com.learn.mq.param.MessageBody;
import com.learn.mq.util.RocketMQMessageSender;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * ClassName:SendMsgController
 * Package:com.learn.mq.controller
 * Description:
 *
 * @Author:@郭先森
 * @Create:2025/7/30 - 17:52
 * @Version:v1.0
 */
@RestController
@Slf4j
public class SendMsgController {

    @Autowired
    private RocketMQMessageSender sender;
    //普通消息同步发送
    @GetMapping("/sendMsg1")
    public boolean sengMsg() throws Exception {
        Person person = new Person(1,"张三",new Date(),'男',"18888888888");
        MessageBody messageBody = new MessageBody();
        messageBody.setIdentifier(String.valueOf(System.currentTimeMillis()));//设置幂等号
        messageBody.setBody(JSON.toJSONString(person));
        Message message = new Message();
        message.setMsgId(String.valueOf(System.currentTimeMillis()));
        message.setBody(JSON.toJSONString(messageBody));
        log.info("封装好的消息为："+message);
        sender.sendMsg("GXC-ROCKETMQ-STARTER","GXS",message);
        return true;
    }
}
